<template>
  <div class="labor">
    <!-- 劳务撮合 -->
    <div class="labor-header">
      <p class="title">劳务撮合板块</p>
    </div>
    <div class="labor-main">
      <!-- 撮合相关数据 -->
      <div class="pairing-data">
        <div class="title">
          <p class="round">
            <span class="inner"></span>
          </p>
          <span class="text">撮合相关数据</span>
          <span class="line"></span>
          <span class="triangle"></span>
          <span class="triangle2"></span>
        </div>
        <div class="data-wrap">
          <div class="item">
            <div class="icon1"></div>
            <div class="content">
              <count-to
                class="val"
                :startVal="0"
                :endVal="personnelCount"
                :duration="1000"
              ></count-to>
              <p class="key">产业工人(人)</p>
            </div>
          </div>
          <div class="item">
            <div class="icon2"></div>
            <div class="content">
              <count-to
                class="val"
                :startVal="0"
                :endVal="resumeCount"
                :duration="1000"
              ></count-to>
              <p class="key">产业工人数字履历(条)</p>
            </div>
          </div>
          <div class="item">
            <div class="icon3"></div>
            <div class="content">
              <count-to
                class="val"
                :startVal="0"
                :endVal="certCount"
                :duration="1000"
              ></count-to>
              <p class="key">产业工人数字证照(张)</p>
            </div>
          </div>
        </div>
      </div>
      <div class="chart-wrap">
        <div class="title">
          <p class="round">
            <span class="inner"></span>
          </p>
          <span class="text">获证人数TOP5</span>
          <span class="line"></span>
          <span class="triangle"></span>
          <span class="triangle2"></span>
        </div>
        <div class="chart">
          <p class="legend-wrap"><span class="legend"></span> 获证人数</p>
          <Echart
            id="labor-chart"
            :options="option"
            height="278px"
            width="100%"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref, onMounted } from "vue";
import Echart from "@/components/echart/index.vue";
import CountTo from "@/components/vueCountTo/vue-countTo.vue";
import { ajax } from "@/store/service";
import opt from "./laborExchangeOpt";

const personnelCount = ref(0);
const resumeCount = ref(0);
const certCount = ref(0);
const option = reactive({ ...opt });

const getArrByKey = (data, k) => {
  let key = k || "value";
  let res = [];
  if (data) {
    data.forEach(function (t) {
      res.push(t[key]);
    });
  }
  return res;
};
const getSymbolData = (data) => {
  let arr = [];
  for (var i = 0; i < data.length; i++) {
    arr.push({
      value: data[i].y,
      symbolPosition: "end",
    });
  }
  return arr;
};
const generateArray = (arr) => {
  const max = Math.max(...arr.map((item) => item.y));
  return Array.from({ length: arr.length }, (_, index) => max);
};

const init = async () => {
  const [res] = await ajax.laborBrokerage();
  personnelCount.value = res.personnelCount;
  resumeCount.value = res.resumeCount;
  certCount.value = res.certCount;
  const { chart } = res;
  option.yAxis[0].data = getArrByKey(chart, "x");
  option.yAxis[1].data = getArrByKey(chart, "x");
  option.series[0].data = getSymbolData(chart); //条形末端圆点
  option.series[1].data = getSymbolData(generateArray(chart)); //背景
  option.series[2].data = getSymbolData(chart); //条
  option.yAxis[0].axisLabel.formatter = (v, i) => "{title|" + chart[i].x + "}";
  option.yAxis[1].axisLabel.formatter = (v, i) =>
    chart[i].y + "{percentNumber|}";
};

onMounted(() => {
  init();
});
</script>

<style scoped lang='scss'>
.labor {
  width: 100%;
  height: 463px;
  .labor-header {
    width: 1114px;
    height: 79px;
    background: url("@/assets/longscreen2/title-long.png");
    box-sizing: border-box;
    padding-top: 14px;
    .title {
      font-size: 22px;
      font-family: JLinXin;
      font-weight: 600;
      line-height: 22px;
      background: #fffde8 linear-gradient(180deg, #e8feff 40%, #00a9ff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      font-weight: bold;
      margin-left: 68px;
    }
  }
  .labor-main {
    padding-left: 29px;
    padding-top: 8px;
    display: flex;

    .pairing-data {
      width: 303px;
      .data-wrap {
        height: 244px;
        padding-top: 17px;
        padding-bottom: 17px;
        padding-left: 10px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .item {
          height: 60px;
          display: flex;
          .icon1 {
            width: 60px;
            height: 60px;
            background: url("@/assets/longscreen2/icon_chanyegongren.png");
          }
          .icon2 {
            width: 60px;
            height: 60px;
            background: url("@/assets/longscreen2/icon_shuzilvli.png");
          }
          .icon3 {
            width: 60px;
            height: 60px;
            background: url("@/assets/longscreen2/icon_shuzizhengzhao.png");
          }
          .content {
            margin-left: 12px;
            .val {
              font-size: 28px;
              font-family: D-DIN-PRO-Heavy, D-DIN-PRO;
              font-weight: 800;
              color: #ffffff;
              letter-spacing: 2px;
              display: block;
              margin-bottom: 4px;
            }
            .key {
              font-size: 16px;
              font-family: SourceHanSansCN-Medium, SourceHanSansCN;
              font-weight: 500;
              color: #ffffff;
              opacity: 0.7;
            }
          }
        }
      }
    }
    .chart-wrap {
      width: 708px;
      margin-left: 60px;
      .chart {
        width: 642px;
        height: 278px;
        margin-left: 28px;
        position: relative;
        .legend-wrap {
          position: absolute;
          right: 0;
          font-size: 14px;
          font-family: SourceHanSansCN-Regular, SourceHanSansCN;
          font-weight: 400;
          color: #ffffff;
          line-height: 21px;
          display: flex;
          align-items: center;
          .legend {
            width: 18px;
            height: 8px;
            display: block;
            background: #19d4e0;
            border-radius: 1px;
            margin-right: 6px;
          }
        }
      }
    }
    .title {
      height: 20px;
      display: flex;
      align-items: center;
      margin-bottom: 44px;
      .round {
        width: 20px;
        height: 20px;
        display: block;
        background: rgba(0, 47, 115, 0.59);
        border: 1px solid #005096;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        .inner {
          width: 8px;
          height: 8px;
          display: block;
          background: #0153c8;
          border-radius: 50%;
          box-shadow: 0px 0px 4px 0px #209aff;
          border: 1px solid #75e7f8;
        }
      }
      .text {
        font-size: 18px;
        font-family: SourceHanSansCN-Bold, SourceHanSansCN;
        font-weight: bold;
        color: #d2f6ff;
        line-height: 27px;
        margin-left: 8px;
      }
      .line {
        flex: 1;
        border-top: 1px solid #19a3bf;
        margin-left: 20px;
      }
      .triangle {
        // background: #b1f9ff;
        opacity: 0.43;
        border-top: 8px solid transparent;
        border-right: 8px solid #b1f9ff;
        border-bottom: 8px solid transparent;
        margin-left: 7px;
      }
      .triangle2 {
        // background: #b1f9ff;
        border-top: 8px solid transparent;
        border-right: 8px solid #b1f9ff;
        border-bottom: 8px solid transparent;
        margin-left: 4px;
      }
    }
  }
}
</style>